<?php
/**
 *网店出售
 */
namespace Mobile\Controller;


use Think\Page;
class CaseController extends MobileBaseController {

    public function index(){
        $where['status']=1;

        $count = M('case')->where($where)->count();
        $page = new Page($count,8);
        $this->assign('page',$page->show());// 赋值分页输出*/
        $order_str = "add_time DESC";
        $list = M('case')->order($order_str)->where($where)->limit($page->firstRow.','.$page->listRows)->select();
        foreach($list AS $k=>$v){
            $goods_id =$v['goods_id'];
            $v['goods']=M('goods')->where("goods_id=$goods_id")->find();
            $list[$k]=$v;
        }


        $this->assign('page',$page->show());
        $this->assign('lists',$list);
        $this->display();

    }

	public function detail(){
        $where['id']=I('id');
        $info = M('case')->where($where)->find();
        $goods_id =$info['goods_id'];
        $goods = M('goods')->where("goods_id=$goods_id")->find();

        //随机查询 4条记录
        $case_where['status']=1;
//        $case_list=M('case')->where($case_where)->order('rand()')->limit(4)->select();
        $case_list=M('case')->where($case_where)->order("add_time DESC")->limit(4)->select();
        $this->assign('case_list',$case_list);
        $this->assign('goods',$goods);
        $this->assign('info',$info);

        $this->display();
    }

}